const express = require('express');
const router = express.Router();

/**
 * 查询所有口味
 * GET /tastes
 */
router.get('/', async (req, res) => {
  try {
    const [rows] = await req.db.query(
      'SELECT taste_id, taste_name FROM tastes ORDER BY taste_id'
    );
    
    res.json({
      code: 1,
      msg: 'success',
      data: rows.map(row => ({
        tasteId: row.taste_id,
        tasteName: row.taste_name
      }))
    });
  } catch (error) {
    console.error('查询口味列表出错:', error);
    res.status(500).json({
      code: 0,
      msg: '查询口味列表失败',
      data: null
    });
  }
});

module.exports = router;